package helperClasses;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Vector;

public class Member implements Serializable, Comparator<Object>
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -8632878014647370914L;
	private String name, password, major, email;
	private Vector<ClassInfo> classList;
	private int type;
	
	public static final int USER = 0;
	public static final int ADMIN = 1;
	
	public Member() {
	}
	
	public Member(String name, String password)
	{
		this.name = name;
		this.password = password;
		classList = new Vector<ClassInfo>();
	}
	
	public Member(String name, String password, String major, String email, int type)
	{
		this.name = name;
		this.password = password;
		this.major = major;
		this.email = email;
		this.type = type;
		classList = new Vector<ClassInfo>();
	}
	
	public Member(Member member) {
		this.name = member.getName();
		this.password = member.getPassword();
		if(member.getMajor() != null)
			this.major = member.getMajor();
		if(member.getEmail() != null)
			this.email = member.getEmail();
		if(member.getClassList() != null)
			this.classList = new Vector<ClassInfo>(member.getClassList());
		this.type = member.getType();
	}
	
	public Member clone() {
		return new Member(this);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMajor() {
		return major;
	}

	public void setMajor(String major) {
		this.major = major;
	}
	
	public String toString() {
		return "Name: " + this.getName() + "\nPassword: " + this.getPassword();
	}

	@Override
	public int compare(Object o1, Object o2) {
		Member h1 = (Member) o1;
		Member h2 = (Member) o2;
		return h1.toString().compareTo(h2.toString());
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPassword() {
		return password;
	}
	
	public void addClass(ClassInfo cla) {
		this.classList.add(cla);
	}
	
	public boolean isClass(ClassInfo cla) {
		return this.classList.contains(cla);
	}
	
	public void removeClass(ClassInfo cla) {
		this.classList.remove(cla);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Member other = (Member) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if(!password.equals(other.password))
			return false;
		return true;
	}

	public void setClassList(Vector<ClassInfo> classList) {
		this.classList = classList;
	}

	public Vector<ClassInfo> getClassList() {
		return classList;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getType() {
		return type;
	}
	
	public Vector<Vector<Object>> classListToVector() {
		Vector<Vector<Object>> vec = new Vector<Vector<Object>>();
		
		for(int count = 0; count < classList.size(); count++)
		{
			vec.add(classList.get(count).toVector());
		}
		
		return vec;
	}
	
	public Vector<Object> toVector() {
		Vector<Object> vec = new Vector<Object>();
		
		vec.add(this.name);
		vec.add(this.type);
		
		return vec;
	}
}
